<?
layout("/inc/layout.html",{title:sysTitle}){
?>
<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">普通词表管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>词表管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">普通词表管理</li>
		</ol>
		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">
		<!-- 知识分类s -->
		<div class="panel panel-white">
			<div class="panel-heading">
				分类： <span class="demo-btn" style="float: right;">
					<button type="button" class="btn btn-sm btn-info btn-outlined"
						onclick="generalWordCategoryList()">分类管理</button>
					<button id="showDataValue" value="0" onclick="tableDiv()" type="button" class="btn btn-sm btn-info btn-outlined">缩略词展示</button>
					<button type="button" class="btn btn-sm btn-info btn-outlined" onclick="wordGeneralImport()">数据导入</button>
					<button type="button" class="btn btn-sm btn-info btn-outlined" onclick="download()">数据导出</button> </span>

			</div>
			<div class="panel-body">
				
				<div class="demo-btn" id="generalWordList">
					
				</div>
			</div>
		</div>

		<!-- 知识分类e -->
		<div class="row">

			<div class="col-lg-12">
				<div class="panel" style="height: auto;overflow: auto;">
					<div class="panel-heading" style="margin-bottom: -10px;">
						数据列表 <span class="subtitle">展示词表数据列表，点击可编辑词表具体条目信息。</span>
						<span class="subtitle" style="float: right;" id="count"> </span>
					</div>
					<div id="suoLueCiShow" class="panel-body" >
						<span class='subtitle' style="font-size: 15px;">数据为空!</span>
					</div>

					<div id="lieBiaoShow" class="panel-body" style="margin-top: 10px">
						<div class="row ">
							<div class="col-lg-6">
								<div class="input-group input-group-sm mbs">
									<span class="input-group-btn"> 
										<select id="queryParams" data-toggle="dropdown" class="btn btn-danger dropdown-toggle" style="width :100px;">
											<option value="wordName" selected="true">词名称</option>
											<option value="wordPinyin">汉语拼音</option>
											<option value="wordEnglish">英文译名</option>
											<option value="wordInitial">词首字母</option>
									</select> </span> <input id="text" type="text" placeholder="请输入关键词..."
										class="form-control" /><span class="input-group-btn">
										<button type="button" data-toggle="dropdown" style="margin-right: 10px;"
											class="btn btn-success dropdown-toggle" onclick="get(1)">精确搜索</button>
										<button type="button" data-toggle="dropdown"
											class="btn btn-success dropdown-toggle" onclick="get(0)">模糊搜索</button>
									</span>
								</div>
							</div>
							<div class="col-lg-6">
								<div class="tb-group-actions pull-right">
									<!-- <span >当前已选择<span id="Xuannum">0</span>条记录:</span> 
					<button class="btn btn-sm btn-primary" onclick="delePiLiang()">
						<i class="fa fa-check"></i>&nbsp; 删除多项
					</button>   -->
									<button id="addXin" name="buValueColor" type="button"
										class="btn btn-green  btn-sm btn-default">新增</button>

								</div>
							</div>
						</div>
						<table style="margin-top: 8px"
							class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
							<thead>
								<tr>
									<th width="50px"  style="text-align:center;white-space:nowrap;">序号</th>
									<th style="white-space:nowrap;">词名称</th>
									<th style="white-space:nowrap;">汉语拼音</th>
									<th style="white-space:nowrap;">英文译名</th>
									<th style="white-space:nowrap;">词首字母</th>
									<th style="white-space:nowrap;">分类名称</th>
									<th style="white-space:nowrap;">可操作</th>
								</tr>
							</thead>
							<tbody id="findGeneralWordLieBiao">
							</tbody>
						</table>
						<div id="dataNull" class="panel-body"
								style="height: 90px; line-height: 50px;" align="center">
								<span class='subtitle' style="font-size: 15px;">数据为空!</span>
						</div>
					</div>
					<div id="page2" style="text-align: center; margin-top: 10px; margin-bottom: 15px;"></div>
				</div>

			</div>

		</div>

	</div>
  <form action="./generalWordExportdownload.do" method="post" name="aa" target="_blank">
  	<input id="generalWordCategoryId" name="generalWordCategoryId" value="" type="hidden"/>
  </form>
  <form action="./exportExcelDict1.do" method="post" name="aa" target="_blank">
  	<input id="generalWordCategoryId" name="generalWordCategoryId" value="" type="hidden"/>
  </form> 
	<!--END CONTENT-->
</div>

<SCRIPT type="text/javascript">
	var GWordCategoryId;
	var wordCategoryid;
	$("#lieBiaoShow").hide();
	$("#spanXinZeng").hide();

	/* $("#showDataValue").toggle(function() {
		$(this).html("列表展示");
		$("#suoLueCiShow").hide();
		$("#lieBiaoShow").show();
		$("#spanXinZeng").show();
		demo1(GWordCategoryId);
	}, function() {
		$(this).html("缩略词展示");
		$("#text").val("");
		$("#queryParams").val("-1");
		$("#suoLueCiShow").show();
		$("#lieBiaoShow").hide();
		$("#spanXinZeng").hide();
		demo1(GWordCategoryId);
	}); */
	function tableDiv(){
		var showDataValue = $("#showDataValue").val();
		if(showDataValue == '0'){
			$("#showDataValue").html("缩略词展示");
			$("#text").val("");
			$("#suoLueCiShow").show();
			$("#lieBiaoShow").hide();
			$("#spanXinZeng").hide();
			demo1(GWordCategoryId);
			var path ="/";
			var expires = new Date();  
		    expires.setTime(expires.getTime() + 7 * 3600000 * 24);  
		    //path=/，表示cookie能在整个网站下使用，path=/temp，表示cookie只能在temp目录下使用  
		    path = path == "" ? "" : ";path=" + path;  
		    //GMT(Greenwich Mean Time)是格林尼治平时，现在的标准时间，协调世界时是UTC  
		    //参数days只能是数字型  
		    var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();  
		    document.cookie = "generalTableType=1" + _expires + path;
		    $("#showDataValue").val('1');
		}else{
			$("#showDataValue").html("列表展示");
			$("#suoLueCiShow").hide();
			$("#lieBiaoShow").show();
			$("#spanXinZeng").show();
			demo1(GWordCategoryId);
			var path ="/";
			var expires = new Date();  
		    expires.setTime(expires.getTime() + 7 * 3600000 * 24);  
		    //path=/，表示cookie能在整个网站下使用，path=/temp，表示cookie只能在temp目录下使用  
		    path = path == "" ? "" : ";path=" + path;  
		    //GMT(Greenwich Mean Time)是格林尼治平时，现在的标准时间，协调世界时是UTC  
		    //参数days只能是数字型  
		    var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();  
		    document.cookie = "generalTableType=0" + _expires + path;
		    $("#showDataValue").val('0');
		}
	}
	/**实现功能，保存用户的登录信息到cookie中。当登录页面被打开时，就查询cookie**/  
	window.onload = function(){  
		var path ="/";
	    var generalTableType = getCookieValue("generalTableType"); 
	    if('' != generalTableType &&  null != generalTableType && undefined != generalTableType){
	    	if(generalTableType == '0'){
	    		$("#showDataValue").html("列表展示");
	    		$("#suoLueCiShow").hide();
	    		$("#lieBiaoShow").show();
	    		$("#spanXinZeng").show();
	    		$("#showDataValue").val('0');
	    		demo1(GWordCategoryId);
				generalTableType = 0;
	    	}else{
	    		$("#showDataValue").html("缩略词展示");
	    		$("#text").val("");
	    		$("#suoLueCiShow").show();
	    		$("#lieBiaoShow").hide();
	    		$("#spanXinZeng").hide();
	    		$("#showDataValue").val('1');
	    		demo1(GWordCategoryId);
				generalTableType = 1;
	    	}
	    }else{
	    	$("#showDataValue").html("列表展示");
    		$("#suoLueCiShow").hide();
    		$("#lieBiaoShow").show();
    		$("#spanXinZeng").show();
    		$("#showDataValue").val('0');
    		demo1(GWordCategoryId);	
	    	generalTableType = 0 ;
	    }
	    var expires = new Date();  
	    expires.setTime(expires.getTime() + 7 * 3600000 * 24);  
	    //path=/，表示cookie能在整个网站下使用，path=/temp，表示cookie只能在temp目录下使用  
	    path = path == "" ? "" : ";path=" + path;  
	    //GMT(Greenwich Mean Time)是格林尼治平时，现在的标准时间，协调世界时是UTC  
	    //参数days只能是数字型  
	    var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();  
	    document.cookie = "generalTableType=" + generalTableType + _expires + path;
	} 
	function getCookieValue(name){  /**获取cookie的值，根据cookie的键获取值**/  
	    //用处理字符串的方式查找到key对应value  
	    var name = escape(name);  
	    //读cookie属性，这将返回文档的所有cookie  
	    var allcookies = document.cookie;         
	    //查找名为name的cookie的开始位置  
	    name += "=";  
	    var pos = allcookies.indexOf(name);      
	    //如果找到了具有该名字的cookie，那么提取并使用它的值  
	    if (pos != -1){                                             //如果pos值为-1则说明搜索"version="失败  
	        var start = pos + name.length;                  //cookie值开始的位置  
	        var end = allcookies.indexOf(";",start);        //从cookie值开始的位置起搜索第一个";"的位置,即cookie值结尾的位置  
	        if (end == -1) end = allcookies.length;        //如果end值为-1说明cookie列表里只有一个cookie  
	        var value = allcookies.substring(start,end); //提取cookie的值  
	        return (value);                           //对它解码        
	    }else{  //搜索失败，返回空字符串  
	        return "";  
	    }  
	}
	var id;
	var generalWordCategoryId;
	function getGeneralWordId() {
		return id;
	}
	function getGWordCategoryId() {
		return generalWordCategoryId;
	}
	function addEditGeneral(lid, gWordCategoryId) {
		id = lid;
		generalWordCategoryId = gWordCategoryId;
		layer.open({
			type : 2,
			area : [ '700px', '593px' ],
			scrollbar : false,
			shadeClose : true,
			fix : false, //不固定
			title : '普通词表管理',
			//maxmin : true,  
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [ "word-general-addEdit.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.Page();
			},
			cancel : function(index) {
			}
		});
	}
	function generalWordCategoryList() {
		layer.open({
			type : 2,
			area : [ '700px', '600px' ],
			scrollbar : false,
			shadeClose : true,
			fix : false, //不固定
			title : '分类管理',
			//maxmin : true,  
			skin : 'layui-layer-rim', //加上边框
			btn : [ '关闭' ],
			content : [ "word-generalWordCategory-list.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.WordList();
			},
			cancel : function(index) {
				generalWordList();
				demo1();
			}
		});
	}
	$(function() {
		generalWordList();
		demo1();
	});
	function generalWordList() {
		$.getJSON("./findAllGeneralWordCategory.do",
			function(res) {
				//此处仅仅是为了演示变化的内容
				var str = "";
				if(res!=null && res!=""){
					$("#generalWordList").html("");
				}else{
					$("#generalWordList").html("<span class='subtitle' style='font-size: 15px;'>数据为空!请新建分类。</span>");
				}
				for ( var i = 0; i < res.length; i++) {
						str += "<button id='"
							+ res[i].id
							+ "' onclick='demo1(GWordCategoryId="
							+ res[i].id+",1"
							+ ")' name='buColor' type='button' style='font-size:11px; height:28px;' class='btn btn-blue btn-sm btn-default'>"
							+ res[i].categoryName + "</button>";
				}

				$("#generalWordList").append(str);
			});
	};
	var curr;
	function get(getType) {
		demo1(GWordCategoryId,curr,getType);
	}
	function demo1(GWordCategoryId,curr,getType) {
	wordCategoryid=GWordCategoryId;
		$("[name='buColor']").attr("class","btn btn-blue btn-sm btn-default"); 
		$.getJSON(
						"./findwordGeneralList.do",
						{
							page : curr || 1,
							queryParams : $("#queryParams").val(),
							text : $("#text").val(),
							GWordCategoryId : GWordCategoryId,
							showType : $("#showDataValue").html(),
							getType : getType,
						},
						function(res) {
							//此处仅仅是为了演示变化的内容
							var suolue = "";
							var liebiao = "";
							if(res.result[0].classTypeRed!=null){
								$("#"+GWordCategoryId).attr("class",res.result[0].classTypeRed); 
							}
							$("#suoLueCiShow").html("");
							$("#findGeneralWordLieBiao").html("");
							if(res.listsize>0){
								$("#dataNull").hide();
							}else{
								$("#dataNull").show();
							}
							for ( var i = 0; i < res.listsize; i++) {
								if(res.result[i].id!=null){
										suolue += "<span  class='demo-btn' id='spanShow' >"
											+ "<button id='"
											+ res.result[i].id
											+ "' name='buValueColor' type='button' onclick=(addEditGeneral("
											+ res.result[i].id
											+ ",(GWordCategoryId="
											+ res.result[i].generalWordCategoryId
											+ ")))"
											+ " class='btn btn-green btn-square' style='margin-top:20px;margin-bottom: -10px; margin-right: 0px;'>"
											+ res.result[i].wordName
											+ "</button>"
											+ "<a  href='javascript:delgeneralWord("
											+ res.result[i].id
											+ ");' style='font-size: 18px; margin-right: 5px;'><i"
										+"style='margin-left: -30px;' class='fa fa-times-circle-o'></i></a></span>";
									liebiao += "<tr><td>"
											+ (i + 1)
											+ "</td><td> <label id=>"
											+ res.result[i].wordName
											+ "</label></td><td><label >"
											+ res.result[i].wordPinyin
											+ "</label></td><td><label >"
											+ res.result[i].wordEnglish
											+ "</label></td><td><label >"
											+ res.result[i].wordInitial
											+ "</label></td><td><label >"
											+ res.result[i].generalWordCategoryName
											+ "</label></td><td>"
											+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"delgeneralWord('"
											+ res.result[i].id
											+ "')\">"
											+ "删除"
											+ "</button>&nbsp;"
											+ "<button type=\"button\" class=\"btn btn-default btn-xs\" onclick=(addEditGeneral("
											+ res.result[i].id
											+ ",(GWordCategoryId="
											+ res.result[i].generalWordCategoryId
											+ ")))>" + "编辑" + "</button>&nbsp;"
											+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"releaseFindGeneralWordId('"
											+ res.result[i].id
											+ "')\">"
											+ "发布"
											+ "</button>"
											+ "</td></tr>";
								}
							}
							$("#addXin").attr(
									"onclick",
									"addEditGeneral(0,(" + GWordCategoryId
											+ "))");
							suolue += "<button  name='buValueColor'  onclick=(addEditGeneral(\"0\",("
									+ GWordCategoryId
									+ ")))"
									+ " type='button' class='btn btn-green btn-square'"
									+ "style='margin-top:20px;margin-bottom: -10px;'>+</button>";
							$("#suoLueCiShow").append(suolue);
							$("#findGeneralWordLieBiao").append(liebiao);
							$("#count").html("词表总数:"+res.count);
							laypage({
								cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
								pages : res.pageSize, //总页数
								skip : true, //是否开启跳页
								skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
								curr : curr || 1,
								last: res.pageSize,
								groups : 6,//连续显示分页数
								jump : function(obj, first) { //触发分页后的回调
									if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
										curr = obj.curr;
										demo1(GWordCategoryId,curr);
									}
								}
							});
						});
	};

	function delgeneralWord(id) {
		if (confirm("是否确认删除！！")) {
			$.ajax({
				type : "post",
				url : "./delgeneralWord.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					layer.msg('删除成功');
					get();
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	
	function wordGeneralImport() {
		layer.open({
			type : 2,
			area : [ '700px', '650px' ],
			scrollbar : false,
			shadeClose : true,
			fix : false, //不固定
			title : '普通词表导入',
			//maxmin : true,  
			skin : 'layui-layer-rim', //加上边框
			btn : [ '导入','关闭'],
			content : [ "word-general-import.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.start();
			},cancel : function(index) {
			}
		});
	}

function download(){

	if (confirm("是否确认导出！！")) {
		  layer.msg('请选择导出格式', {
		  btn: ['xml', 'Excel'],
		  yes: function(index){
		    layer.close(index);
		    var _downiframe = $("iframe#_downiframe");
			if (_downiframe.length == 0) {
				_downiframe =$("<iframe id='_downiframe' name='_downiframe' style='display:none'></iframe>").appendTo($("body"));
			}
			_downiframe.attr("src", "exportXmlGeneralWord.do?wordCategoryid="+wordCategoryid+"&type=xml");
		  },
		  cancel : function(index) {
		  	var _downiframe = $("iframe#_downiframe");
			if (_downiframe.length == 0) {
				_downiframe =$("<iframe id='_downiframe' name='_downiframe' style='display:none'></iframe>").appendTo($("body"));
			}
			_downiframe.attr("src", "exportExcelGeneralWord.do?id="+wordCategoryid+"&type=Excel");
			
		  }
		});
	}
	
}

//单个发布
function releaseFindGeneralWordId(generalWordId){
	$.ajax({
			type : "post",
			url : "releaseFindGeneralWordId.do",
			data : {
				"generalWordId":generalWordId,
			},
			dataType : "json",
			success : function(data) {
				if(data[0].data == 'yes'){
					layer.msg('发布成功！');
				}else{
					layer.msg('发布失败！');
				}
				
			},
			error : function(data) {
				layer.msg('请求失败！');
			}
		});
}
</SCRIPT>


<?} ?>

